﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.SYS.Goods
{
    public partial class Form_Bat_Supplier_Price : FormPage
    {
        BLL.Goods bll = new BLL.Goods();
        Model.Goods model = new Model.Goods();
        //
        BLL.Pic bllPic = new BLL.Pic();
        BLL.Brand bllBrand = new BLL.Brand();
        //
        BLL.V_Goods bllV_Goods = new BLL.V_Goods();
        BLL.Goods_BuyPrice_Log bllBuyPrice_Log = new BLL.Goods_BuyPrice_Log();
        BLL.Goods_SellPrice_Log bllSellPrice_Log = new BLL.Goods_SellPrice_Log();
        int SupplierID;
        protected void Page_Load(object sender, EventArgs e) {
            SupplierID = DataTypePlus.requestInt(Request.QueryString["SupplierID"]); 
        }
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel() {  }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default()
        {
            
        }
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {
            
        }
        /// <summary>
        /// 提交
        /// </summary>
        public override void Form_Submit()
        {
            decimal PCT = Convert.ToDecimal(tb_PCT.Text)/100;
            if (PCT < 0 || PCT == 1) { Master.ScriptManager_Alert_float("请正确输入", false); return; }
            foreach (Model.Goods goods in bll.GetModelList("SupplierID=" + SupplierID))
            {
                goods.BuyPrice = goods.BuyPrice * PCT;
                goods.SellPrice = goods.SellPrice * PCT;
                goods.SuggestStorePrice = goods.SuggestStorePrice * PCT;
                bll.Update(goods);

                Model.Goods_BuyPrice_Log modelBuyPrice_Log = new Model.Goods_BuyPrice_Log();
                modelBuyPrice_Log.GoodsID = goods.id;
                modelBuyPrice_Log.PriceAfter = model.BuyPrice;
                int BuyPrice_LogID_new = bllBuyPrice_Log.Add(modelBuyPrice_Log);
                BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.Goods_BuyPrice_Log, BuyPrice_LogID_new, EnumHelper.OperateType.Add, "");

                Model.Goods_SellPrice_Log modelSellPrice_Log = new Model.Goods_SellPrice_Log();
                modelSellPrice_Log.GoodsID = goods.id;
                modelSellPrice_Log.PriceAfter = model.SellPrice;
                int SellPrice_LogID_new = bllSellPrice_Log.Add(modelSellPrice_Log);
                BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.Goods_SellPrice_Log, SellPrice_LogID_new, EnumHelper.OperateType.Add, "");

                
            }
              Master.SubmitOK();

            
        }
    }
}